package cn.edu.sdjzu.xg.bysj.service;

import cn.edu.sdjzu.xg.bysj.dao.OpenAreaDao;
import cn.edu.sdjzu.xg.bysj.domain.OpenArea;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;


public class OpenAreaService {
    private static OpenAreaDao openAreaDao= OpenAreaDao.getInstance();
    private static OpenAreaService openAreaService=new OpenAreaService();
    private OpenAreaService(){}

    public static OpenAreaService getInstance(){
        return openAreaService;
    }
    public Collection<OpenArea> findAll(List conditionList, Pagination pagination) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Collection<OpenArea> openAreas = openAreaDao.findAll(connection,conditionList,pagination) ;
        JdbcHelper.close(connection);
        return openAreas;
    }

    public OpenArea find(Integer id) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        OpenArea openArea = openAreaDao.find(id,connection);
        JdbcHelper.close(connection);
        return openArea;
    }

    public boolean update(OpenArea openArea) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Boolean updated = openAreaDao.update(openArea,connection);
        JdbcHelper.close(connection);
        return updated;
    }

    public boolean add(OpenArea openArea) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Boolean added = openAreaDao.add(openArea,connection);
        JdbcHelper.close(connection);
        return added ;
    }
    public boolean delete(Integer id) throws SQLException{
        Connection connection = JdbcHelper.getConn();
        boolean deleted = openAreaDao.delete(id, connection);
        JdbcHelper.close(connection);
        return deleted;
    }

    public boolean delete(OpenArea openArea) throws SQLException{
        Connection connection = JdbcHelper.getConn();
        boolean deleted = openAreaDao.delete(openArea, connection);
        JdbcHelper.close(connection);
        return deleted;
    }
}
